import type { AddressItem, AddressParams } from '@/types/address'
import { http } from '@/utils/http'

/**
 * 添加收货地址 或 修改收货地址
 * @param id 地址id(路径参数)
 * @param data 请求参数
 */
export const postMemberAddressByIdAPI = (data: AddressParams,id?:string) => {
    if(id){
        return http({
            method: 'PUT',
            url: `/member/address/${id}`,
            data,
          })
    }else{
        return http({
            url:'/member/address',
            method:'POST',
            data
        })
    }
}

/**
 * 获取收货地址列表
 */
export const getMemberAddressAPI = () => {
    return http<AddressItem[]>({
      url: '/member/address',
      method: 'GET',
    })
}


  /**
 * 获取收货地址详情
 * @param id 地址id(路径参数)
 */
export const getMemberAddressByIdAPI = (id: string) => {
    return http<AddressItem>({
      url: `/member/address/${id}`,
      method: 'GET',
    })
}


/**
 * 删除收货地址
 * @param id 地址id(路径参数)
 */
export const deleteMemberAddressByIdAPI = (id: string) => {
    return http({
      method: 'DELETE',
      url: `/member/address/${id}`,
    })
}